<?php

class fastBuyService extends CWidget {

    public function run() {
        $cats = Yii::app()->params['categories'];
        foreach ($cats as $cat) {
            $options[$cat['pageId']] = $cat['pageTitle'];
        }
        $this->render('fastBuyService', array('options' => $options));
    }

    public function getBrands($categoryID) {
        if ($categoryID > 0) {
            $criteria = new CDbCriteria();
            $criteria->select = '"pageId", "pageTitle"';
            $criteria->addCondition('"pageParent" = \'' . $categoryID . '\' and "pageType" = \'brand\' order by "pageTitle"');
            $models = Page::model()->findAll($criteria);
            return CHtml::listData($models, 'pageId', 'pageTitle');
        }
        return array();
    }

    public function getModels($brandID) {
        if ($brandID > 0) {
            $criteria = new CDbCriteria();
            $criteria->select = '"pageId", "pageTitle"';
            $criteria->addCondition('"pageParent" = \'' . $brandID . '\' and "pageType" = \'model\' order by "pageTitle"');
            $models = Page::model()->findAll($criteria);
            return CHtml::listData($models, 'pageId', 'pageTitle');
        }
        return array();
    }

    public function getServices($modelID) {
        if ($modelID > 0) {
            $criteria = new CDbCriteria();
            $regionId = Yii::app()->session['userRegion']['id'];
            $criteria->select = '"serviceId", "serviceTitle"';
            $criteria->addCondition('"modelId" = \'' . $modelID . '\' and "regionId" = \'' . $regionId . '\' order by "serviceTitle"');
            $tblName = !Yii::app()->user->isGuest ? 'Model2servAll' : 'Model2servAll_new';
            $models = $tblName::model()->findAll($criteria);
            return CHtml::listData($models, 'serviceId', 'serviceTitle');
        }
        return array();
    }

}
